package com.design.pattern.state.base;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author 王霄
 * @date 2022/3/10 21:01
 */
public class CarStateManager {

    private final static Map<StateEnum, CarState> CAR_STATE_SERVICE_MAP = new HashMap<>();

    public CarStateManager(List<CarState> carStateList) {
        carStateList.forEach(carState -> CAR_STATE_SERVICE_MAP.putIfAbsent(carState.getState(), carState));
    }

    public CarState get(StateEnum stateEnum) {
        return CAR_STATE_SERVICE_MAP.get(stateEnum);
    }
}
